<?php /*a:1:{s:97:"D:\phpstudy\PHPTutorial\WWW\niege\myapp\second\app_admin\tp5\application\index\view\user\add.html";i:1616639553;}*/ ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <script src="/layui/layui.js"></script>
</head>
<body>
<form class="layui-form" id="editForm">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名:</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input field-username"  id="title" lay-verify="name" name="name" placeholder="请输入用户名" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码:</label>
        <div class="layui-input-inline">
            <input type="password" class="layui-input field-username" id="password" lay-verify="password" name="password" placeholder="请输入密码">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">职务:</label>
        <div class="layui-input-inline">
            <select name="city" value="">
                <?php foreach($job as $value): if($value['name'] !== "超级管理员"): ?>
                         <option value="<?php echo htmlentities($value['id']); ?>"><?php echo htmlentities($value['name']); ?></option>
                    <?php endif; ?>
                <?php endforeach; ?>
            </select>
        </div>
    </div>

    <br>

    <div class="layui-form-item" style="padding-left: 110px">
        <button type="submit" class="layui-btn layui-btn-normal" lay-submit  lay-filter="add">添加</button>
    </div>

</form>
<script>
    layui.use(['form'], function() {
        var $ = layui.jquery,
            form = layui.form;
//表单验证我们对表单的验证进行了非常巧妙的支持，大多数时候你只需要在表单元素上加上 lay-verify="" 属性值即可。如：codelayui.code

        form.verify({
            name: function(value){ //value：表单的值、item：表单的DOM对象
                if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
                    return '用户名不能有特殊字符';
                }
                if(/(^\_)|(\__)|(\_+$)/.test(value)){
                    return '用户名首尾不能出现下划线\'_\'';
                }
                if(/^\d+\d+\d$/.test(value)){
                    return '用户名不能全为数字';
                }

                //如果不想自动弹出默认提示框，可以直接返回 true，这时你可以通过其他任意方式提示（v2.5.7 新增）
                if(value === 'xxx'){
                    alert('用户名不能为敏感词');
                    return true;
                }
            }
            ,password: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
        });


        form.on("submit(add)",function(data){
            layer.msg('用户添加中...', {
                time: 2000 //2秒关闭（如果不配置，默认是3秒）
            }, function(){
                $.ajax({
                    url:"<?php echo url('add'); ?>",
                    type:"POST",
                    data:data.field,
                    dataType:"JSON",
                    success (res) {
                        layer.msg(res.msg);
                        setTimeout(function(){
                            layer.closeAll();
                            if (res.code == 1){
                                var index = parent.layer.getFrameIndex(window.name);//关闭当前页面
                                window.parent.location.reload();
                                parent.layer.close(index);
                            }
                        },1000);
                    }
                })
            });
            return false;
        })

    });

</script>

</body>
</html>